const Base = require('../base.js');

module.exports = class extends Base {
  /**
   * @api {get} /leavelist 获取机构列表
   * @apiName SearchUser
   * @apiGroup userinfo
   *
   * @apiSuccess {Number} id 机构id
   *
   * @apiSuccess {String} name 机构名称
   *
   * @apiSuccessExample Success-Response:
   *     HTTP/1.1 200 OK
   *     [{
   *       "id": 2,
   *       "name": "西安研发中心"
   *     }]
   *
   */
  async getAction() {
    try {
      const id = this.get('id');
      const approverArray = id.split(',');
      const user = think.model('userinfo/user');
      const approverArrayList = approverArray.map((e) => {
        return `id = ${e}`;
      });
      const userData = await user.where(approverArrayList.join(' OR ')).field('id, realname').select();
      this.body = userData;
    } catch (error) {
      this.fail('502');
      think.logger.debug(error);
    }
  }
};
